<style>
  @import "../utils/base.scss";

  .demo-tree-render {
    padding-right: 8px;
    padding-left: 8px;
    width: 100%;
  }

  .left_tree {
    padding-top: 20px;
    width: 50%;
    height: calc(100vh - 118px);
    border-right: 1px solid #dcdae2;
    overflow-y: auto;
    overflow-x: hidden;
    float: left;
    /* overflow-x: hidden; */
  }

  .right_info {

    padding-left: 16px;
    padding-top: 20px;
    width: 50%;
    height: calc(100vh - 118px);
    /* border: 1px solid #dcdae2; */
    overflow-y: auto;
    /* overflow-x: hidden; */
  }

  .list-body {
    width: 100%;
    height: 400px;
    font-size: 14px;
    border: 1px solid #dcdae2;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
  }

  .list-header {
    padding: 8px 16px;
    background: #f9fafc;
    color: #515a6e;
    overflow: hidden;
    top: 0;
    left: 0;
    width: 100%;
  }

  .transfer-list {
    line-height: 1.5;
    display: inline-block;
    width: 36%;
    height: 400px;
    font-size: 14px;
    vertical-align: middle;
    position: relative;
    padding-top: 35px;
  }

  .transfer-list-header {
    padding: 8px 16px;
    background: #f9fafc;
    color: #515a6e;
    border: 1px solid #dcdee2;
    border-bottom: 1px solid #e8eaec;
    border-radius: 6px 6px 0 0;
    overflow: hidden;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
  }

  .transfer-list-body {
    height: 100%;
    border: 1px solid #dcdee2;
    border-top: none;
    border-radius: 0 0 6px 6px;
    position: relative;
    overflow: hidden;
  }

  .transfer-operation {
    display: inline-block;
    margin: 0 16px;
    vertical-align: middle;
  }

  .transfer-list-body-with-search {
    padding-top: 34px;
  }

  .transfer-list-body-content {
    padding: 6px 0 0;
    height: 100%;
    padding: 4px 0;
    overflow: auto;
  }

  .transfer-list-content-item:hover {
    background: #f3f3f3;
  }

  .transfer-list-content-not-found {
    display: block;
    text-align: center;
    color: #c5c8ce;
  }

  .transfer-list-content-item {
    margin: 0;
    line-height: normal;
    padding: 7px 16px;
    clear: both;
    color: #515a6e;
    font-size: 14px !important;
    white-space: nowrap;
    list-style: none;
    cursor: pointer;
    transition: background 0.2s ease-in-out;
  }

  .transfer-list-body-search-wrapper {
    padding: 8px 8px 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
  }

  .ivu-tree-title {
    user-select: none;
    width: 100%;
    overflow-x: hidden;
  }
</style>
<template>
  <div>
    <pheader>
      <template slot="left">用户管理/组织架构</template>
    </pheader>
    <div style="padding: 8px 8px 0px 8px;">
      <div
        style="width: 100%;background-color: white;height: calc(100vh - 108px);overflow-y: hidden;padding:10px 0px 10px;">
        <div class="left_tree">
          <Tree :data="allDept" :check-directly="true" :render="renderContent" class="demo-tree-render"></Tree>
        </div>
        <div class="right_info">
          <div style="padding-right:22px;padding-bottom: 40px;">
            <Button v-if="!edit" type="primary" style="right:50px;float:right;" size="small"
              @click="edit=true">编辑</Button>
            <Button v-if="edit" style="right:50px;float:right;" size="small" @click="cancelEdit">取消</Button>
            <Button v-if="edit" type="primary" style="right:55px;float:right; margin-right: 4px;" size="small"
              @click="changeDept()">保存</Button>
          </div>
          <div>
            <Form ref="add_menu" :model="rigthInfo" label-position="left" :label-width="100">
              <Row >
                <Col span="23"style="width:97%" >
                <FormItem label="组织名称：" prop="role_name">
                  <Input v-model="rigthInfo.gName" :readonly="!edit" />
                </FormItem>
                </Col>
              </Row>
              <Row >
                <Col span="23" style="width:97%">
                <FormItem label="组织描述：" prop="des">
                  <Input v-model="rigthInfo.des" type="textarea" :readonly="!edit" :rows="3" />
                </FormItem>
                </Col>
              </Row>
              <Row >
                <Col span="23" style="width:97%">
                <FormItem label="部门领导：" prop="des">
                  <template v-if="!edit">
                    <span v-if="rigthInfo.checkLeader.length == 0" style="color: #c5c8ce;"> 暂无</span>
                    <Tag v-else v-for="(item,k1) in rigthInfo.checkLeader" :key="k1">
                      {{rigthInfo.leaderList.find(e=>e.id==item).user_name}}</Tag>
                  </template>
                  <Select v-show="edit" ref="select" v-model="rigthInfo.checkLeader" loading-text="搜索中..."
                    not-found-text="无相关人员" multiple filterable remote :remote-method="searchLeader"
                    :label="rigthInfo.checkLeader" :loading="leaderLoading">
                    <Option v-for="(option, index) in rigthInfo.leaderList" :value="option.id" :key="index">
                      {{option.user_name}}</Option>
                  </Select>
                </FormItem>
                </Col>
              </Row>
              <!-- <Row >
                                <Col span="23" style="width:97%">
                                    <FormItem label="组织成员：" prop="des">
                                        <Transfer
                                            :data="searchData"
                                            :target-keys="targetKeys"
                                            :list-style="listStyle"
                                            :render-format="render2"
                                            :titles="['未授权','已添加']"
                                            :operations="['移除','新增']"
                                            :filterable="true"
                                            :filter-method="searchUser"
                                            @on-change="handleChange">
                                        </Transfer>
                                    </FormItem>
                                </Col>
                            </Row> -->
              <Row>
                <Col span="23" style="width:97%">
                <FormItem label="组织成员：" prop="des">
                  <div v-show="!edit" class="list-body">
                    <div class="list-header" style="height: 50px">
                      <Input style="margin: 0 !important;float: left;width: 40%" height="50" clearable
                        @on-clear="onClear" search v-model="leftInput" @keydown.enter.native.prevent
                        @on-search="searchUser" placeholder="搜索人员名称">
                      </Input>
                      <span style="margin: 0 !important;float: right;">{{"共 "+rightInfoListTemp.length+" 人" }}</span>
                    </div>
                    <ul class="transfer-list-body-content" style="height: 88%;">
                      <template v-if="rightInfoList.length > 0">
                        <template v-for="item in rightInfoList">
                          <li class="transfer-list-content-item">
                            <span style="margin-left: 8px">{{item.user_name + (item.isleader == 1 ? "(领导)":'')}}</span>
                          </li>
                        </template>
                      </template>
                      <li v-else class="transfer-list-content-not-found">列表为空</li>
                    </ul>
                  </div>
                  <div v-show="edit">
                    <div class="transfer-list">
                      <div class="transfer-list-header">
                        <Checkbox v-model="leftCheckAll" @on-change="leftAllCheck" :disabled="leftInfoList.length < 1">
                        </Checkbox>
                        <span class="ivu-transfer-list-header-title">未授权</span>
                        <span class="ivu-transfer-list-header-count">{{leftInfoList.length}}</span>
                      </div>
                      <div class="transfer-list-body transfer-list-body-with-search">
                        <div class="transfer-list-body-search-wrapper">
                          <Input search v-model="leftInput" size="small" @on-search="addSearchUser"
                            placeholder="新增人员名称">
                          <!-- <Icon type="ios-contact" slot="prefix" /> -->
                          </Input>
                        </div>
                        <ul class="transfer-list-body-content">
                          <template v-if="leftInfoList.length > 0">
                            <CheckboxGroup v-model="leftCheckList" @on-change="leftCheck">
                              <template v-for="item in leftInfoList">
                                <li class="transfer-list-content-item">
                                  <Checkbox :label="item.id"><span
                                      style="margin-left: 8px">{{item.user_name + (item.isleader == 1 ? "(领导)":'')}}</span>
                                  </Checkbox>
                                </li>
                              </template>
                            </CheckboxGroup>
                          </template>
                          <li v-else class="transfer-list-content-not-found">{{leftNotFindMsg}}</li>
                        </ul>
                      </div>
                    </div>
                    <div class="transfer-operation ">
                      <Button :disabled="rightCheckList.length == 0" type="primary" size="small" @click="dleRight()">
                        <Icon type="ios-arrow-back" style="padding-right:4px" /><span>移除</span>
                      </Button>
                      <Button :disabled="leftCheckList.length == 0" type="primary" style="display: block;margin-top:8px"
                        size="small" @click="addRight()">新增
                        <Icon type="ios-arrow-forward" style="padding-left:4px" />
                      </Button>
                    </div>
                    <div class="transfer-list">
                      <div class="transfer-list-header">
                        <Checkbox v-model="rightCheckAll" @on-change="rightAllCheck"
                          :disabled="rightInfoList.length < 1"></Checkbox>
                        <span class="ivu-transfer-list-header-title">已授权</span>
                        <span class="ivu-transfer-list-header-count">{{rightInfoListTemp.length}}</span>
                      </div>
                      <div class="transfer-list-body transfer-list-body-with-search">
                        <div class="transfer-list-body-search-wrapper">
                          <Input @on-clear="backList" clearable search v-model="rightInput" size="small"
                            @keydown.enter.native.prevent @on-search="searchUser" placeholder="搜索人员名称" />
                        </div>
                        <ul class="transfer-list-body-content">
                          <template v-if="rightInfoList.length > 0">
                            <CheckboxGroup v-model="rightCheckList" @on-change="rightCheck">
                              <template v-for="item in rightInfoList">
                                <li class="transfer-list-content-item">
                                  <Checkbox :label="item.id"><span
                                      style="margin-left: 8px">{{item.user_name + (item.isleader == 1 ? "(领导)":'')}}</span>
                                  </Checkbox>
                                </li>
                              </template>
                            </CheckboxGroup>
                          </template>
                          <li v-else class="transfer-list-content-not-found">列表为空</li>
                        </ul>
                      </div>
                    </div>
                  </div>
                </FormItem>
                </Col>
              </Row>
            </Form>

          </div>
        </div>
      </div>
    </div>
    <!-- <Modal
                    width="710"
                    title="组织成员管理"
                    scrollable
                    v-model="modal"
                    class-name="vertical-center-modal" @on-ok="addUser">
                    <Row >
                        <Col span="24">
                            <Input search enter-button placeholder="搜索授权人员" @on-search="searchUser" />
                        </Col>
                    </Row>

                </Modal> -->
    <Modal @on-ok="addDept()" @on-cancel="deptShow =false" v-model="deptShow" :title="'新增部门'" width="720">
      <Form ref="add_menu" :model="deptInfo" label-position="left" :label-width="100">
        <Row v-if="!deptEdit">
          <Col span="23"style="width:97%" >
          <FormItem label="父级部门：" prop="role_name">
            <Input v-model="deptInfo.pName" :readonly="true" />
          </FormItem>
          </Col>
        </Row>
        <Row >
          <Col span="23"style="width:97%" >
          <FormItem label="部门名称：" prop="role_name">
            <Input v-model="deptInfo.gName"  />
          </FormItem>
          </Col>
        </Row>
        <Row >
          <Col span="23" style="width:97%">
          <FormItem label="部门描述：" prop="des">
            <Input v-model="deptInfo.des" type="textarea" :rows="3" />
          </FormItem>
          </Col>
        </Row>
      </Form>
    </Modal>
    <Modal v-model="isDel" width="360" @on-ok="delDept" class-name="vertical-center-modal" :closable="false">
      <div style="text-align:center;font-size:16px;">
        <p>是否确定删除该部门?</p>
      </div>
    </Modal>
  </div>
</template>
<script>
  import pheader from "../comp_chatter/pheader"
  import ajax from "../ajax_util"

  export default {
    components: {
      pheader
    },
    data() {
      return {
        edit: false,
        leftNotFindMsg: "列表为空",
        leftCheckAll: false, //左边全选按钮
        leftCheckList: [], //左边选择集合
        leftInfoList: [], //左边数据集合
        leftInput: "", //左边搜索值

        rightCheckAll: false, //右边全选按钮
        rightCheckList: [], //右边选择集合
        rightInfoList: [], //右边数据集合
        rightInput: "", //右边搜索值
        rightInfoListTemp: [], //右边选择框原始数据

        listStyle: {
          width: '250px',
          height: '400px'
        },
        targetKeys: [],
        searchData: [],
        allDept: [],

        buttonProps: {
          type: 'default',
          size: 'small',
        },
        data: {}, //需要操作的节点数据
        isDel: false, //显示是否删除
        delParent: {}, //需要删除的父类
        delIndex: 0, //需要删除的下标
        deptShow: false, //显示组织
        deptEdit: false, //编辑
        append1status: false, // 是否新增同级部门
        firstDept: false, //是否是最高部门
        deptInfo: {
          id: -1,
          fatherId: -1,
          pName: "",
          gName: "",
          des: ""
        },
        leaderLoading: false,
        rigthInfo: {
          id: -1,
          gName: "",
          des: "",
          leaderList: [],
          checkLeader: [],
          userList: []
        },
        showData: "", //右边显示的原始数据
      }
    },
    computed: {},
    mounted() {
      this.getAllDept()
    },
    methods: {

      onClear() {
        this.rightInfoList = this.rightInfoListTemp
      },
      // 新增
      addRight() {
        this.leftCheckList.forEach(item => {
          this.leftInfoList.forEach((i, index) => {
            if (i.id == item) {
              this.rightInfoList.push(i)
              this.leftInfoList.splice(index, 1)
            }
          })
        })
        this.leftCheckList = []
        if (this.leftCheckAll) {
          this.leftCheckAll = false
        }
      },
      // 移除
      dleRight() {
        var t = JSON.stringify(this.rightInfoList)
        var temp = JSON.parse(t)
        this.rightCheckList.forEach(item => {
          this.rightInfoList.forEach((i, index) => {
            if (i.id == item) {
              this.leftInfoList.push(i)
              temp.splice(index, 1)
            }
          })
          this.rightInfoListTemp.forEach((i, index) => {
            if (i.id == item) {
              this.rightInfoListTemp.splice(index, 1)
            }
          })
        })
        this.rightCheckList = []

        this.rightInfoList = this.rightInfoListTemp
        this.rightInput = ""
        if (this.rightCheckAll) {
          this.rightCheckAll = false
        }
      },
      // 清楚输入框时回复右边是数据
      backList() {
        this.rightInfoList = this.rightInfoListTemp
      },
      // 右边多选按钮控制
      rightCheck(value) {
        if (value.length == this.rightInfoList.length && !this.rightCheckAll) {
          this.rightCheckAll = true
        } else if (value.length != this.rightInfoList.length && this.rightCheckAll) {
          this.rightCheckAll = false
        }
      },
      // 右边全选按钮控制
      rightAllCheck(value) {
        if (value) {
          var temp = []
          this.rightInfoList.forEach(item => {
            temp.push(item.id)
          })
          this.rightCheckList = temp
        } else {
          this.rightCheckList = []
        }
      },
      //右边搜索人员
      searchUser(value) {
        if (value != '') {
          //console.log(value)
          var tempList = []
          this.rightInfoListTemp.forEach((item, index) => {
            if (item.user_name.indexOf(value) != -1) {
              tempList.push(item)
            }
          })
          this.rightInfoList = tempList
        } else {
          this.rightInfoList = this.rightInfoListTemp
        }
      },

      // 左边多选按钮控制
      leftCheck(value) {
        if (value.length == this.leftInfoList.length && !this.leftCheckAll) {
          this.leftCheckAll = true
        } else if (value.length != this.leftInfoList.length && this.leftCheckAll) {
          this.leftCheckAll = false
        }
      },
      // 左边全选按钮控制
      leftAllCheck(value) {
        if (value) {
          var temp = []
          this.leftInfoList.forEach(item => {
            temp.push(item.id)
          })
          this.leftCheckList = temp
        } else {
          this.leftCheckList = []
        }
      },
      //左边搜索人员
      addSearchUser(value) {
        if (value != "") {
          var that = this;
          var url = this.CONFIG.url_know + "/searchUser/" + value;
          ajax.get({
            url: url,
            that: that,
            params: null,
            success: function(data) {
              that.leftInfoList = []
              data.forEach(item => {
                var t = that.rightInfoList.find(e => e.id == item.id)
                if (t === undefined) {
                  that.leftInfoList.push(item)
                } else {
                  that.leftNotFindMsg = "该用户已在部门下"
                }
              })
            }
          })
        }
      },
      render1(row) {
        return row.user_name + "_" + row.company + "_" + row.department
      },

      handleChange(newTargetKeys) {
        this.targetKeys = newTargetKeys;
      },
      render2(row) {
        var temp = row.user_name
        if (row.isleader == 1) {
          temp += "(领导)"
        }
        return temp
      },
      //获取所有的组织信息
      getAllDept() {
        var that = this;
        var url = this.CONFIG.url_know + '/structs';
        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            //console.log(data)
            that.allDept = data
            that.showInfo(data[0])

          }
        })
      },
      //自定义tree内容
      renderContent(h, {
        root,
        node,
        data
      }) {
        return h('span', {
          style: {
            display: 'inline-block',
            width: '100%',
            overflowX: 'hidden'
          },
          class: 'ivu-tree-title',

        }, [
          h('p', {
            style: {
              width: '44%',
              textOverflow: 'ellipsis',
              whiteSpace: 'nowrap',
              overflow: 'hidden',
              float: 'left'
            },
            on: {
              click: () => {
                this.showInfo(data)
              }
            }
          }, data.title),
          h('span', {
            style: {
              display: 'inline-block',
              float: 'right',
              marginRight: '10px',
            }
          }, [
            h('Button', {
              props: Object.assign({}, this.buttonProps, {
                icon: 'ios-add'
              }),
              style: {
                marginRight: '8px',
                color: '#000',
                fontWeight: '400'
              },

              on: {
                click: () => {
                  this.append1(root, node, data)
                }
              }
            }, "同级部门", ),
            h('Button', {
              props: Object.assign({}, this.buttonProps, {
                icon: 'ios-add'
              }),
              style: {
                marginRight: '8px',
                color: '#000',
                fontWeight: '400'
              },
              on: {
                click: () => {
                  this.append2(data)
                }
              }
            }, "下级部门", ),
            h('Button', {
              props: Object.assign({}, this.buttonProps, {
                // icon: 'ios-remove'
              }),
              style: {
                color: '#000',
                fontWeight: '400'
              },
              on: {
                click: () => {
                  this.remove(root, node, data)
                }
              }
            }, "删除", )
          ])
        ], );
      },
      //显示右边内容
      showInfo(data) {
        this.edit = false
        //console.log("------------>",data)
        this.data = data
        var that = this;
        var url = this.CONFIG.url_know + '/structs/' + this.data.id;
        ajax.get({
          url: url,
          that: that,
          cache: true,
          cacheTime: 60,
          success: function(data) {
            var t = JSON.stringify(data)
            that.showData = t
            that.$nextTick(() => {
              that.setRightInfo(JSON.parse(t))
            })
            // that.getDeptUser(data.id)
          }
        })

      },
      setRightInfo(data) {
        this.rigthInfo.id = data.id
        this.rigthInfo.gName = data.gName
        this.rigthInfo.des = data.des
        this.searchData = []
        this.targetKeys = []
        this.rightInfoList = data.users
        this.rightInfoListTemp = data.users
        this.rigthInfo.leaderList = []
        this.rigthInfo.checkLeader = []
        data.users.forEach(item => {
          if (item.isleader == 1) {
            this.rigthInfo.leaderList.push(item)
            this.rigthInfo.checkLeader.push(item.id)
          }
          // this.rigthInfo.leaderList.push(item)
          // this.rigthInfo.checkLeader.push(item.id)
        })
        this.setChangeStatus()
      },
      //切换部门时设置右边显示的值
      setChangeStatus() {
        this.leftCheckAll = false //左边全选按钮
        this.leftCheckList = [] //左边选择集合
        this.leftInfoList = [] //左边数据集合
        this.leftInput = "" //左边搜索值

        this.rightCheckAll = false //右边全选按钮
        this.rightCheckList = [] //右边选择集合
        this.rightInput = ""
      },

      append1(root, node, data) {
        //console.log("data--------->",data)
        this.deptShow = true
        this.append1status = true
        const parentKey = root.find(el => el === node).parent;
        //console.log(parentKey)
        if (parentKey != undefined) {
          const parent = root.find(el => el.nodeKey === parentKey).node;
          this.deptInfo.pName = parent.title
          this.deptInfo.fatherId = parent.id
          this.data = parent
        } else {
          //console.log(this.data)
          this.firstDept = true
          this.deptInfo.pName = "无"
          this.deptInfo.fatherId = 0
          this.data = this.deptInfo
        }



      },
      //显示新增组织
      append2(data) {
        //console.log("data--------->",data)
        this.deptShow = true
        this.append1status = false

        this.deptInfo.pName = data.title
        this.deptInfo.fatherId = data.id
        this.data = data

      },
      //新增组织
      addDept() {
        var that = this;
        var temp = {
          fatherId: that.deptInfo.fatherId,
          gName: that.deptInfo.gName,
          des: that.deptInfo.des,
        }

        var url = this.CONFIG.url_know + '/struct';

        ajax.post({
          url: url,
          that: that,
          data: temp,
          success: function(data1) {
            if (data1 == 0) {
              that.$Notice.error({
                title: '新增失败',
                desc: '请刷新后重试'
              });
              that.deptInfo = {
                pid: -1,
                pName: "",
                gName: "",
                des: ""
              }
              that.data = {}
              that.firstDept = false
            } else if (data1 == -1) {
              that.$Notice.error({
                title: '新增失败',
                desc: '连接4A超时，请联系相关负责人'
              });
              that.deptInfo = {
                pid: -1,
                pName: "",
                gName: "",
                des: ""
              }
              that.data = {}
              that.firstDept = false
            } else {
              that.$Message.success('新增成功!');
              var data = that.data
              //console.log("data..--.....>",that.firstDept)
              if (that.firstDept) {
                var t = JSON.stringify(that.allDept)
                var temp = JSON.parse(t)
                temp.push({
                  title: that.deptInfo.gName,
                  id: data1,
                  expand: true
                })
                that.$nextTick(() => {
                  that.allDept = temp
                })
                //console.log(that.allDept)
                // that.$set(this.allDept, 'children', children);
              } else {
                const children = data.children || [];
                children.push({
                  title: that.deptInfo.gName,
                  id: data1,
                  expand: true
                });
                that.$set(data, 'children', children);
              }
              that.deptInfo = {
                pid: -1,
                pName: "",
                gName: "",
                des: ""
              }
              that.data = {}
              that.firstDept = false
            }
          }
        })

      },
      //删除
      remove(root, node, data) {
        const temp = root.find(el => el.nodeKey === data.nodeKey).node;

        if (data.children != undefined && data.children.length > 0) {
          this.$Message.warning('该组织下有部门，无法删除!');
        } else {
          const parentKey = root.find(el => el === node).parent;
          this.isDel = true
          if (parentKey != undefined) {
            const parent = root.find(el => el.nodeKey === parentKey).node;
            const index = parent.children.indexOf(data);
            this.delParent = parent
            this.index = index
          } else {
            this.delParent = this.allDept
            this.index = this.allDept.indexOf(data)
            this.firstDept = true
          }
        }
        this.data = data
      },
      delDept() {
        var that = this;
        var url = this.CONFIG.url_know + '/struct/' + this.data.id;
        ajax.del({
          url: url,
          that: that,
          data: null,
          success: function(data) {
            if (data == "1") {
              that.$Message.warning('删除成功!');
              if (that.firstDept) {
                that.delParent.splice(that.index, 1);
              } else {
                that.delParent.children.splice(that.index, 1);
              }
              that.firstDept = false
            } else if (data == "0") {
              that.$Notice.error({
                title: '删除失败',
                desc: '该组织下有用户'
              });
              that.firstDept = false
            } else {
              that.$Notice.error({
                title: '删除失败',
                desc: data
              });
              that.firstDept = false
            }
          }
        })
      },
      // 取消编辑
      cancelEdit() {
        this.$refs.select.setQuery()
        //console.log("-0----------")
        this.edit = false
        this.$nextTick(() => {
          this.setRightInfo(JSON.parse(this.showData))
        })
      },
      // 保存
      changeDept() {
        var that = this;
        var url = this.CONFIG.url_know + '/struct';
        that.rigthInfo.users = []
        that.rightInfoList.forEach(item => {
          item.isleader = 0
          that.rigthInfo.users.push({
            id: item.id,
            isleader: 0
          })
        })
        if (that.rigthInfo.checkLeader.length > 0) {
          that.rigthInfo.checkLeader.forEach(item => {
            //console.log(that.rigthInfo.users)
            var temp = that.rigthInfo.users.find(e => e.id == item)
            //console.log("temp ---->",temp)
            if (temp != undefined) {
              temp.isleader = 1
            } else {
              that.rigthInfo.users.push({
                id: item,
                isleader: 1
              })

            }
            var b = that.rightInfoList.find(e => e.id == item)
            if (b != undefined) {
              b.isleader = 1
            } else {
              var c = that.rigthInfo.leaderList.find(e => e.id == item)
              c.isleader = 1
              that.rightInfoList.push(c)
            }
          })
        }
        ajax.put({
          url: url,
          that: that,
          data: that.rigthInfo,
          success: function(data1) {
            if (data1 == "1") {
              that.$Message.success('修改成功!');
              that.$nextTick(() => {
                var data = that.data

                that.$set(data, 'title', that.rigthInfo.gName);
                that.edit = false
              })
              that.setChangeStatus()
            } else {
              that.$Notice.error({
                title: '修改失败',
                desc: data1
              });
            }
          }
        })
      },
      // 查找领导
      searchLeader(name) {
        //console.log(name)
        if (name != "") {
          this.leaderLoading = true
          this.utils.delay(() => {
            var that = this;
            var url = this.CONFIG.url_know + "/searchUser/" + name;
            ajax.get({
              url: url,
              that: that,
              params: null,
              success: function(data) {
                if (data.length > 0) {
                  data.forEach(item => {
                    if (that.rigthInfo.leaderList.find(e => e.id === item.id) == undefined) {
                      that.rigthInfo.leaderList.push(item)
                    }
                  })
                }
                that.$nextTick(() => {
                  that.leaderLoading = false
                })
              }
            })
          }, 500)
        }
      },
    }
  }
</script>
